<template>
  <el-dialog
    :title="!dataForm.uid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="分类（博客/问答/评论）" prop="reportType">
      <el-input v-model="dataForm.reportType" placeholder="分类（博客/问答/评论）"></el-input>
    </el-form-item>
    <el-form-item label="被举报人uid" prop="reporuUserUid">
      <el-input v-model="dataForm.reporuUserUid" placeholder="被举报人uid"></el-input>
    </el-form-item>
    <el-form-item label="uid" prop="reportContentUid">
      <el-input v-model="dataForm.reportContentUid" placeholder="uid"></el-input>
    </el-form-item>
    <el-form-item label="举报人uid" prop="userUid">
      <el-input v-model="dataForm.userUid" placeholder="举报人uid"></el-input>
    </el-form-item>
    <el-form-item label="进展状态: 0 未处理   1: 已查看  2：已处理" prop="progress">
      <el-input v-model="dataForm.progress" placeholder="进展状态: 0 未处理   1: 已查看  2：已处理"></el-input>
    </el-form-item>
    <el-form-item label="状态  （0 删除  1正常）" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态  （0 删除  1正常）"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="违规类型" prop="violationType">
      <el-input v-model="dataForm.violationType" placeholder="违规类型"></el-input>
    </el-form-item>
    <el-form-item label="举报内容" prop="content">
      <el-input v-model="dataForm.content" placeholder="举报内容"></el-input>
    </el-form-item>
    <el-form-item label="举报的原文" prop="reportContent">
      <el-input v-model="dataForm.reportContent" placeholder="举报的原文"></el-input>
    </el-form-item>
    <el-form-item label="是否删除:0否 1是" prop="isDelete">
      <el-input v-model="dataForm.isDelete" placeholder="是否删除:0否 1是"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          uid: 0,
          reportType: '',
          reporuUserUid: '',
          reportContentUid: '',
          userUid: '',
          progress: '',
          status: '',
          createTime: '',
          updateTime: '',
          violationType: '',
          content: '',
          reportContent: '',
          isDelete: ''
        },
        dataRule: {
          reportType: [
            { required: true, message: '分类（博客/问答/评论）不能为空', trigger: 'blur' }
          ],
          reporuUserUid: [
            { required: true, message: '被举报人uid不能为空', trigger: 'blur' }
          ],
          reportContentUid: [
            { required: true, message: 'uid不能为空', trigger: 'blur' }
          ],
          userUid: [
            { required: true, message: '举报人uid不能为空', trigger: 'blur' }
          ],
          progress: [
            { required: true, message: '进展状态: 0 未处理   1: 已查看  2：已处理不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态  （0 删除  1正常）不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          violationType: [
            { required: true, message: '违规类型不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '举报内容不能为空', trigger: 'blur' }
          ],
          reportContent: [
            { required: true, message: '举报的原文不能为空', trigger: 'blur' }
          ],
          isDelete: [
            { required: true, message: '是否删除:0否 1是不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.uid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.uid) {
            this.$http({
              url: this.$http.adornUrl(`/user/report/info/${this.dataForm.uid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.reportType = data.report.reportType
                this.dataForm.reporuUserUid = data.report.reporuUserUid
                this.dataForm.reportContentUid = data.report.reportContentUid
                this.dataForm.userUid = data.report.userUid
                this.dataForm.progress = data.report.progress
                this.dataForm.status = data.report.status
                this.dataForm.createTime = data.report.createTime
                this.dataForm.updateTime = data.report.updateTime
                this.dataForm.violationType = data.report.violationType
                this.dataForm.content = data.report.content
                this.dataForm.reportContent = data.report.reportContent
                this.dataForm.isDelete = data.report.isDelete
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/user/report/${!this.dataForm.uid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'uid': this.dataForm.uid || undefined,
                'reportType': this.dataForm.reportType,
                'reporuUserUid': this.dataForm.reporuUserUid,
                'reportContentUid': this.dataForm.reportContentUid,
                'userUid': this.dataForm.userUid,
                'progress': this.dataForm.progress,
                'status': this.dataForm.status,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'violationType': this.dataForm.violationType,
                'content': this.dataForm.content,
                'reportContent': this.dataForm.reportContent,
                'isDelete': this.dataForm.isDelete
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
